<?php
        require_once ("../include/class.pdoSio.inc.php");
            
        
        
            if (isset($_POST['inputNom'])) {
                $nom = htmlspecialchars($_POST['inputNom']);
                if (preg_match("#^([a-zA-Z'àâéèêôùûçÀÂÉÈÔÙÛÇ\s-]{1,30})$#", $nom)){
                    $champVerif = true;
                } else { $champVerif = false;}
            }
            if (isset($_POST['inputPrenom'])) {
                $prenom = htmlspecialchars($_POST['inputPrenom']);
                if (preg_match("#^([a-zA-Z'àâéèêôùûçÀÂÉÈÔÙÛÇ\s-]{1,30})$#", $prenom)){
                    $champVerif = true;
                } else { $champVerif = false;}
            }
            if (isset($_POST['inputAdresseRue'])) {
                $adresseRue = htmlspecialchars($_POST['inputAdresseRue']);
            }
            if (isset($_POST['inputAdresseCp'])) {
                $adresseCp = htmlspecialchars($_POST['inputAdresseCp']);
                if (preg_match('#^[0-9]{4,5}$#', $adresseCp)) {
                    $champVerif = true;
                } else { $champVerif = false;}
            }
            if (isset($_POST['inputAdresseVille'])) {
                $adresseVille = htmlspecialchars($_POST['inputAdresseVille']);
                if (preg_match('#[a-zéèêëàâîïôöûü-]+$#', $adresseVille)) {
                    $champVerif = true;
                } else { $champVerif = false;}
            }
            if (isset($_POST['inputTelPerso'])) {
                $telPerso = htmlspecialchars($_POST['inputTelPerso']);
                if (preg_match("#^0[1_9]([-. ]?[0-9]{2}){4}$#", $telPerso)) {
                    $champVerif = true;
                } else { $champVerif = false;}
            }
            if (isset($_POST['inputTelPro'])) {
                $telPro = htmlspecialchars($_POST['inputTelPro']);
                if (preg_match("#^0[1_9]([-. ]?[0-9]{2}){4}$#", $telPerso)) {
                    $champVerif = true;
                } else { $champVerif = false;}
            }
            if (isset($_POST['inputEmail'])) {
                $courriel = htmlspecialchars($_POST['inputEmail']);
                if (preg_match("#^[a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\\.[a-z]{2,4}$#", $courriel)) {
                    $champVerif = true;
                } else { $champVerif = false;}
            }
            
            if (isset($_POST['inputSite'])) {
                $site = htmlspecialchars($_POST['inputSite']);
            }
            if (isset($_POST['inputAnneeEntreePromo'])) {
                $anneeEntree = htmlspecialchars($_POST['inputAnneeEntreePromo']);
                if (preg_match("#^[12][0-9]{3}$#", $anneeEntree)) {
                    $champVerif = true;
                } else { $champVerif = false;}
            }
            if (isset($_POST['inputAnneeSortiePromo'])) {
                $anneeSortie = htmlspecialchars($_POST['inputAnneeSortiePromo']);
                if (preg_match("#^[12][0-9]{3}$#", $anneeSortie)) {
                    $champVerif = true;
                } else { $champVerif = false;}
            }
            if (isset($_POST['inputLogin'])) {
                $identifiant = htmlspecialchars($_POST['inputLogin']);
                if (preg_match("#^[A-Za-z][A-Za-z0-9]{1,31}$#", $identifiant)) {
                    $champVerif = true;
                } else { $champVerif = false;}
            }
            if (isset($_POST['inputMdp'])) {
                $mdp = md5($_POST['inputMdp']);
                $champVerif = true;
            } else { $champVerif = false;}

            if ($champVerif === true){
            $pdo = PdoSio::getPdoSio();
            $resultats = $pdo->ajoutUtilisateur($nom, $prenom, $adresseRue, $adresseCp, $adresseVille, $telPerso, $telPro, $courriel, $site, $anneeEntree, $anneeSortie, $identifiant, $mdp);
            if($resultats){
            echo "1";}
            } else {echo "-1";}